package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQueryObject;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;


    @RequestMapping("/list")
    public String query(Model model,@ModelAttribute("qo") TravelQueryObject qo){

        Page page = travelService.query(qo);
        model.addAttribute("page",page);
        return "/travel/list";
    }

    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Travel travel){
        travelService.changeState(travel);

        return JsonResult.success();
    }

    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id){
        String content = travelService.getContentById(id);

        return JsonResult.success(content);
    }


}
